//
//  YKProductInfoViewController.m
//  YunKang
//
//  Created by leoking870 on 2017/11/7.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKProductInfoViewController.h"
#import "YKClientListHeaderView.h"
#import "AuditDetailHeaderView.h"
#import "YKProductInfoModel.h"
#import "YKClientNeedsItem.h"
#import "YKApproveBottomView.h"
@interface YKProductInfoViewController ()
@property (nonatomic, strong) YKProductInfoModel *mYKProductInfoModel;
@end

@implementation YKProductInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"商品价格审批";
    AuditDetailHeaderView *header = (AuditDetailHeaderView *)[[NSBundle mainBundle]loadNibNamed:@"AuditDetailHeaderView" owner:nil options:nil].firstObject;
    [self.view addSubview:header];
    [header mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.equalTo(self.view);
    }];
    
    YKClientListHeaderView* headerView = [[YKClientListHeaderView alloc]initWithTitles:@[@"类型",@"原值",@"新值"] weights:@[@2,@1,@1]];
    
    headerView.textFont = [UIFont systemFontOfSize:16];
    [self.view addSubview:headerView];
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.view);
        make.top.equalTo(header.mas_bottom);
    }];
    headerView.backgroundColor = [UIColor tf_colorWithHexString:@"#1EADFC"];
    
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.bottom.trailing.equalTo(self.view);
        make.top.equalTo(headerView.mas_bottom);
    }];
    
    [self tf_showStateView:kTFViewStateLoading];
    [TFHTTPMANAER POST:@"product/searchProductInfoById.htm" parameters:@{@"businessId":self.businessId?:@""} success:^(id responseObject) {
        self.mYKProductInfoModel = [YKProductInfoModel yy_modelWithJSON:responseObject[@"prodMap"]];
        [self updateView];
        header.model = self.mYKProductInfoModel;
        [self tf_showStateView:kTFViewStateNone];
    } failure:^(id responseObject, NSError *error) {
        [self tf_showStateView:kTFViewStateNetError];
    }];
    
    [YKApproveBottomView addSelfToView:self ID:self.businessId approveStatus:self.approveStatus];
    
}

- (void)updateView {
    YKClientNeedsModel *model1 = [YKClientNeedsModel new];
    model1.C_NAME = @"零售价";
    model1.DRUGSNAME = self.mYKProductInfoModel.RETAIL_PRICE;
    model1.CREATETIME = self.mYKProductInfoModel.RETAIL_PRICE_WH;
    
    YKClientNeedsModel *model2 = [YKClientNeedsModel new];
    model2.C_NAME = @"基准价";
    model2.DRUGSNAME = self.mYKProductInfoModel.WHOLE_PRICE;
    model2.CREATETIME = self.mYKProductInfoModel.WHOLE_PRICE_WH;
    
    YKClientNeedsModel *model3 = [YKClientNeedsModel new];
    model3.C_NAME = @"底限价";
    model3.DRUGSNAME = [NSString stringWithFormat:@"%.2f",self.mYKProductInfoModel.LOWEST_PRICE];
    model3.CREATETIME = [NSString stringWithFormat:@"%.2f", self.mYKProductInfoModel.LOWEST_PRICE_WH];
    
    YKClientNeedsModel *model4 = [YKClientNeedsModel new];
    model4.C_NAME = @"采购价";
    model4.DRUGSNAME = self.mYKProductInfoModel.PURCHASE_PRICE;
    model4.CREATETIME = self.mYKProductInfoModel.PURCHASE_PRICE_WH;
    
    YKClientNeedsModel *model5 = [YKClientNeedsModel new];
    model5.C_NAME = @"赠积分";
    model5.DRUGSNAME = self.mYKProductInfoModel.PERFORMANCE_POINTS?:@"0";
    model5.CREATETIME = self.mYKProductInfoModel.PERFORMANCE_POINTS_WH?:@"0";
    
    TFTableViewSection *section = [TFTableViewSection section];
    section.headerHeight = .1f;
    section.footerHeight = .1f;
    [section addItem:[YKClientNeedsItem itemWithModel:model1]];
    [section addItem:[YKClientNeedsItem itemWithModel:model2]];
    [section addItem:[YKClientNeedsItem itemWithModel:model3]];
    [section addItem:[YKClientNeedsItem itemWithModel:model4]];
    [section addItem:[YKClientNeedsItem itemWithModel:model5]];
    
    [self.tableViewManager addSection:section];
    [self.tableView reloadData];
}
@end
